﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Vehicle.Web.Pages.Expense
{
    /// <summary>
    /// Copyright (C) M-Tear团队
    /// 文 件 名：Expense_Add.aspx.cs
    /// 版    本：v1.00.0000
    /// 创建标识：2009-09-02   Created by 杨光远 V1.00.0000
    /// 功能说明：车队运输成本添加类
    /// 注意事项：无
    /// 
    /// 更新记录：
    /// 
    /// </summary>
    public partial class Expense_Add : Component.PageBase
    {
        #region---基本变量实例化---
        Vehicle.BLL.Expense b_Expense = new Vehicle.BLL.Expense();
        BLL.Log b_Log = new Vehicle.BLL.Log();
        Vehicle.Model.ExpenseInfo m_ExpenseInfo=new Vehicle.Model.ExpenseInfo();
        #endregion

        #region---基本操作---
        /// <summary>
        /// 页面加载事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                ExpenseDataBind();//绑定数据
            }
        }
        /// <summary>
        /// 费用信息绑定
        /// </summary>
        public void ExpenseDataBind()
        {
            try
            {
                txt_C_ID.Text = b_Expense.GetModel(new Vehicle.Model.ComponentsInfo("Task", "T_ID", Request.QueryString["id"].ToString(), "T_ID")).Rows[0]["C_Card"].ToString();//绑定承运单编号
            }
            catch
            {
                txt_C_ID.Text = "无";
            }
            try
            {
                txt_T_ID.Text = b_Expense.GetModel(new Vehicle.Model.ComponentsInfo("Task", "T_ID", Request.QueryString["id"].ToString(), "T_ID")).Rows[0]["T_Num"].ToString();//绑定任务单编号
            }
            catch
            {
                txt_T_ID.Text = "无";
            }
            try
            {
                txt_M_ID.Text = b_Expense.GetModel(new Vehicle.Model.ComponentsInfo("Motorcade", "M_ID", b_Expense.GetModel(new Vehicle.Model.ComponentsInfo("Task", "T_ID", Request.QueryString["id"].ToString(), "T_ID")).Rows[0]["M_ID"].ToString(), "M_ID")).Rows[0]["M_Name"].ToString();//绑定车对名称
            }
            catch
            {
                txt_M_ID.Text = "无";
            }
            try
            {

                txt_V_ID.Text = b_Expense.GetModel(new Vehicle.Model.ComponentsInfo("Vehicles", "V_ID", b_Expense.GetModel(new Vehicle.Model.ComponentsInfo("Task", "T_ID", Request.QueryString["id"].ToString(), "T_ID")).Rows[0]["V_ID"].ToString(), "V_ID")).Rows[0]["V_LicenseNum"].ToString();//绑定车牌号
            }
            catch
            {
                txt_V_ID.Text = "无";
            }
            try
            {
                txt_P_ID.Text = b_Expense.GetModel(new Vehicle.Model.ComponentsInfo("Pilot", "P_ID", b_Expense.GetModel(new Vehicle.Model.ComponentsInfo("Task", "T_ID", Request.QueryString["id"].ToString(), "T_ID")).Rows[0]["P_ID"].ToString(), "P_ID")).Rows[0]["P_Name"].ToString();//绑定驾驶员姓名
            }
            catch
            {
                txt_P_ID.Text = "无";
            }
            }
        /// <summary>
        /// 添加数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btn_Add_Click(object sender, EventArgs e)
        {
            m_ExpenseInfo.C_ID = Vehicle.Common.TextHelper.StringToInt(b_Expense.GetModel(new Vehicle.Model.ComponentsInfo("Cargo", "C_Card", b_Expense.GetModel(new Vehicle.Model.ComponentsInfo("Task", "T_ID", Request.QueryString["id"].ToString(), "T_ID")).Rows[0]["C_Card"].ToString(), "C_ID")).Rows[0]["C_ID"].ToString());//承运单ID
            m_ExpenseInfo.T_ID = Vehicle.Common.TextHelper.StringToInt(Request.QueryString["id"].ToString());
            m_ExpenseInfo.M_ID = Vehicle.Common.TextHelper.StringToInt(b_Expense.GetModel(new Vehicle.Model.ComponentsInfo("Task", "T_ID", Request.QueryString["id"].ToString(), "T_ID")).Rows[0]["M_ID"].ToString());//车队ID
            m_ExpenseInfo.V_ID = Vehicle.Common.TextHelper.StringToInt(b_Expense.GetModel(new Vehicle.Model.ComponentsInfo("Task", "T_ID", Request.QueryString["id"].ToString(), "T_ID")).Rows[0]["V_ID"].ToString());//任务单ID
            m_ExpenseInfo.P_ID = Vehicle.Common.TextHelper.StringToInt(b_Expense.GetModel(new Vehicle.Model.ComponentsInfo("Task", "T_ID", Request.QueryString["id"].ToString(), "T_ID")).Rows[0]["P_ID"].ToString());//驾驶员ID
            m_ExpenseInfo.E_All = Vehicle.Common.TextHelper.StringTofloat(txt_E_All.Text.Trim());//运输总费用
            m_ExpenseInfo.E_personal = Vehicle.Common.TextHelper.StringTofloat(txt_E_personal.Text.Trim());//劳务费
            m_ExpenseInfo.E_SCost = Vehicle.Common.TextHelper.StringTofloat(txt_E_SCost.Text.Trim());//保险费
            m_ExpenseInfo.E_TCost = Vehicle.Common.TextHelper.StringTofloat(txt_E_TCost.Text.Trim());//运输费
            m_ExpenseInfo.E_Incidental = Vehicle.Common.TextHelper.StringTofloat(txt_E_Incidental.Text.Trim());//杂费
            m_ExpenseInfo.E_LastTime = DateTime.Now;//最后修改时间
            m_ExpenseInfo.E_IsDelete = 0;//是否删除  1删除 0不删除
            m_ExpenseInfo.E_Time = DateTime.Now;//添加时间
            b_Expense.Add(m_ExpenseInfo);
            b_Log.Add(new Vehicle.Model.LogInfo(session_ID, DateTime.Now, "成功录入承运成本"));//添加日志
            Common.MessageHelper.AlertRedirect("录入成本成功", "Main.aspx");
        } 
        #endregion
    }
}
